package com.ruoyi.household.service.impl;

import com.ruoyi.buildings.domain.SysBuildings;
import com.ruoyi.buildings.service.ISysBuildingsService;

import com.ruoyi.common.core.domain.model.LoginBody;

import com.ruoyi.common.service.HouseholdAndService;

import com.ruoyi.household.domain.SysHousehold;
import com.ruoyi.household.service.ISysHouseholdService;


import com.ruoyi.usertask.domain.SysUserTask;
import com.ruoyi.usertask.service.ISysUserTaskService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class HouseholdAndServiceImpl implements HouseholdAndService {
    @Autowired
    private ISysHouseholdService sysHouseholdService;

    @Autowired
    private ISysUserTaskService sysUserTaskService;
    @Autowired
    private ISysBuildingsService sysBuildingsService;

    @Override
    public void add(LoginBody loginBody) {
        String buildings = loginBody.getBuildings();
        SysHousehold sysHousehold = new SysHousehold();
        sysHousehold.setAddress(loginBody.getAddress());
        sysHousehold.setBuildingName(buildings);
        sysHousehold.setCommunityName(loginBody.getCommunity());
        sysHousehold.setName(loginBody.getUsername());
        sysHousehold.setTel(loginBody.getPhonenumber());
        sysHousehold.setStatus(0L);
        sysHouseholdService.insertSysHousehold(sysHousehold);
        //关联住户任务表
        SysUserTask sysUserTask = new SysUserTask();
        String name = sysHousehold.getName();
        String buildingName = sysHousehold.getBuildingName();
        sysUserTask.setName(buildingName+"的"+name);
        //根据楼栋名获取楼栋id

//        SysBuildings sysBuildings = sysBuildingsService.selectNameByBuilding(buildings);
//        sysUserTask.setBuildingId(sysBuildings.getUserId());


        sysUserTaskService.insertSysUserTask(sysUserTask);
    }
}
